#include<iostream>
#include <string>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
typedef struct node{
    char data;
    struct node *lchild;
    struct node *rchild;
}BTNode;
int GetHeight( BTNode *BT );
BTNode *CreateBT1(char *pre,char *in,int n);
int main(){
	BTNode *b; 
	int n,i;
	cin>>n;
	char ch,pre[50],in[50];
	for(i=0;i<n;i++){
		cin>>pre[i];
	}
	for(i=0;i<n;i++){
		cin>>in[i];
	}
	b=CreateBT1(pre,in,n);
	cout<<GetHeight(b);
	
}
BTNode *CreateBT1(char *pre,char *in,int n){
	BTNode *b;
	char *p;
	int k;
	if(n<=0) return NULL;
	b=(BTNode*)malloc(sizeof(BTNode));
	b->data=*pre;
	for(p=in;p<in+n;p++){
		if(*p==*pre)
		break;
	}
	k=p-in;
	b->lchild=CreateBT1(pre+1,in,k);
	b->rchild=CreateBT1(pre+k+1,p+1,n-k-1);
	return b;
}
int GetHeight( BTNode *BT ){
	int HL,HR,MaxH;
	if(BT){ 
		HL=GetHeight(BT->lchild);
		HR=GetHeight(BT->rchild);
		MaxH=HL>HR ? HL:HR;
		return MaxH+1;
	}
	else return 0;
}
